package cn.tedu.ivos.geofence.controller;


import cn.tedu.ivos.base.exception.ServiceException;
import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import cn.tedu.ivos.vehicle.mapper.VehicleMapper;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/geofence")
@Tag(name = "围栏模块")
@Validated
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;


    @Operation(summary = "查询围栏")
    @ApiOperationSupport(order = 10)
    @GetMapping("/select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery){
        log.debug("查询围栏：传入参数={}"+geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }

    @Operation(summary = "修改电子围栏状态")
    @ApiOperationSupport(order = 20)
    @PostMapping("/update/{geofenceId}/{status}")
    public JsonResult updateStatus(@PathVariable Long geofenceId, @PathVariable String status){
        log.debug("修改电子围栏状态：geofenceId={},status={}", geofenceId, status);
        geofenceService.updateStatus(geofenceId, status);
        return JsonResult.ok();
    }

    @Operation(summary = "删除电子围栏")
    @ApiOperationSupport(order = 30)
    @PostMapping("/delete/{geofenceId}")
    public JsonResult deleteGeo(@PathVariable Long geofenceId){
        log.debug("删除电子围栏：geofenceId={}", geofenceId);
        geofenceService.deleteGeo(geofenceId);
        return JsonResult.ok();
    }

    @Operation(summary = "新增电子围栏")
    @ApiOperationSupport(order = 40)
    @PostMapping("/save")
    public JsonResult saveGeo(@Validated GeofenceSaveParam geofenceSaveParam){
        log.debug("新增电子围栏：传入参数={}", geofenceSaveParam);
        geofenceService.saveGeo(geofenceSaveParam);
        return JsonResult.ok();
    }

}
